package Single_redmoney2;

import java.util.List;

public class PeopleGetred extends Thread {
    private List<Integer> list;
    public PeopleGetred(List<Integer>list,String name){
        super(name);
        this.list=list;
    }
    @Override
    public void run() {
        String name=Thread.currentThread().getName();
        while (true) {
        synchronized (list) {
            if (list.size() == 0) {
                break;
            }
            int index = (int) (Math.random() * list.size());
            int money= list.remove(index);
            System.out.println(name + " get " + money);
            if (list.size() == 0) {
                break;
            }
            }
        }
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}